package com.thoughtworks.mail;

public class MailWrapper extends NativeLoader{

    private long pointer;

    private long nextPointer;

    private Mail mail;

    public MailWrapper(long pointer, boolean isHead){
        this.pointer = pointer;
        this.nextPointer = this.nativeGetNextPointer(this.pointer);
        if (!isHead) {
            mail = new Mail();
            mail.setNoteId(this.nativeGetNoteId(this.pointer));
            mail.setSender(this.nativeGetSender(this.pointer));
            mail.setReceivers(this.nativeGetReceivers(this.pointer).split(","));
            mail.setCopyTo(this.nativeGetCopyTo(this.pointer).split(","));
            mail.setBlindCopyTo(this.nativeGetBlindCopyTo(this.pointer).split(","));
            mail.setSubject(this.nativeGetSubject(this.pointer));
            mail.setBody(this.nativeGetBody(this.pointer));
            mail.setAttachments(this.nativeGetAttachments(this.pointer).split(";"));
            mail.setPostedDate(this.nativeGetPostedDate(this.pointer));
        }
        this.nativeDestroy(this.pointer);
    }

    private native long nativeGetNextPointer(long pointer);

    private native long nativeGetNoteId(long pointer);

    private native String nativeGetSender(long pointer);

    private native String nativeGetReceivers(long pointer);

    private native String nativeGetCopyTo(long pointer);

    private native String nativeGetBlindCopyTo(long pointer);

    private native String nativeGetSubject(long pointer);

    private native String nativeGetBody(long pointer);

    private native String nativeGetAttachments(long pointer);

    private native String nativeGetPostedDate(long pointer);

    private native void nativeDestroy(long pointer);

    public long getNextPointer() {
        return nextPointer;
    }

    public Mail getMail() {
        return mail;
    }
}
